package cn.lingyangwl.agile.infra.group.controller;

import cn.lingyangwl.agile.infra.group.service.*;
import cn.lingyangwl.agile.infra.module.group.model.rqrs.*;
import cn.lingyangwl.framework.core.response.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * 通用数据组 - 只有查询接口无权鉴权就可以访问, 需要在网关配置, 因为这个查询不是敏感数据, 所以无需鉴权
 * 
 * @author shenguangyang
 */
@Api(tags = "通用数据组")
@RestController
@RequestMapping("/dataGroup")
public class DataGroupController {
    @Resource
    private DataGroupService dataGroupService;

    @ApiOperation(value = "分页通用数据组")
    @GetMapping("/page")
    public Resp<IPage<DataGroupDto>> pageDataGroup(@Validated DataGroupPageReq req) {
        return Resp.ok(dataGroupService.pageGroup(req));
    }

    @ApiOperation(value = "通过id查找通用数据组")
    @GetMapping("/get")
    public Resp<DataGroupDto> getDataGroup(@RequestParam(value = "id") Long id) {
        return Resp.ok(dataGroupService.getGroup(id));
    }

    @ApiOperation(value = "查询通用数据组树")
    @GetMapping("/listTree")
    public Resp<List<DataGroupTreeDto>> listDataGroupTree(@Validated DataGroupQuery req) {
        return Resp.ok(dataGroupService.listGroupTree(req));
    }

    @ApiOperation(value = "查询通用数据组树")
    @GetMapping("/list")
    public Resp<List<DataGroupDto>> listDataGroup(@Validated DataGroupQuery req) {
        return Resp.ok(dataGroupService.listGroup(req));
    }

    @ApiOperation(value = "查询通用数据组子节点")
    @PostMapping("/listChildren")
    public Resp<List<DataGroupDto>> listChildrenGroup(@RequestParam(value = "parentId") Long parentId) {
        return Resp.ok(dataGroupService.listChildrenGroup(parentId));
    }
  
    @ApiOperation(value = "保存通用数据组")
    @PostMapping("/save")
    public Resp<?> saveDataGroup(@RequestBody DataGroupSaveReq req) {
        return Resp.ok(dataGroupService.saveGroup(req));
    }
  
    @ApiOperation(value = "更新通用数据组")
    @PostMapping("/update")
    public Resp<?> updateDataGroup(@RequestBody DataGroupUpdateReq req) {
        return Resp.ok(dataGroupService.updateGroup(req));
    }
  
    @ApiOperation(value = "批量删除通用数据组")
    @DeleteMapping("/batchDelete")
    public Resp<?> batchDeleteDataGroup(@RequestParam("bizType") Integer bizType, @RequestParam(value = "ids") List<Long> ids) {
        DataGroupDeleteReq req = new DataGroupDeleteReq();
        req.setBizType(bizType).setIds(ids);
        return Resp.ok(dataGroupService.deleteGroup(req));
    }
  
    @ApiOperation(value = "删除通用数据组")
    @DeleteMapping("/delete")
    public Resp<?> deleteDataGroup(@RequestParam("bizType") Integer bizType, @RequestParam(value = "id") Long id) {
        DataGroupDeleteReq req = new DataGroupDeleteReq();
        req.setBizType(bizType).setIds(Collections.singletonList(id));
        return Resp.ok(dataGroupService.deleteGroup(req));
    }
}
